package server

import (
	"encoding/json"
	"fmt"
	"net/http"
	"xuper-reins-go/based"
)

var cr ContCR

func setAccess(w http.ResponseWriter) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
}

// 获取前端数据
func getContCR(w http.ResponseWriter, r *http.Request) {
	setAccess(w)
	json.NewDecoder(r.Body).Decode(&cr)

	var EnCRMap = GetContCR1()
	based.TestNativeContract(EnCRMap)
}

// 处理前端数据
func GetContCR1() map[string]string {
	var enCR = processContCR(cr)
	var EnCRMap = convertMap(enCR)
	return EnCRMap
}

func Run() {
	server := http.NewServeMux()

	AddHandletoServer(server, "reinsuranceCon.html")
	server.HandleFunc("/reinsuranceCon", getContCR)
	fmt.Println("peer initial done!")
}
